define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
		
        index: function () {
			
			// 初始化表格参数配置
			Table.api.init({
				extend: {
					table: 'test',
				}
			});
			var table = $("#table");
			 //当表格数据加载完成时
			
			table.bootstrapTable({
				url: '/order_List.json',
				columns: [{
					operate:false,//模糊查询不显示
					field: '',
					title: __('订单'),
					formatter: Controller.api.order_info
				},{
					operate:false,//模糊查询不显示
					field: '',
					title: __('服务'),
					formatter: Controller.api.serve_name
				},{
					operate:false,//模糊查询不显示
					field: '',
					title: __('单价'),
					formatter: Controller.api.serve_price
				},{
					operate:false,//模糊查询不显示
					field: '',
					title: __('数量'),
					formatter: Controller.api.serve_count
				},{
					operate:false,//模糊查询不显示
					field: '',
					title: __('技师'),
					formatter: Controller.api.serve_technician
				},
				{
					visible:false,
					field: 'orderid',
					title: __('订单编号'),
				}, 
				{
					visible:false,//列表不显示,模糊查询显示
					field: 'ordertime',
					title: __('下单日期'),
					operate: 'RANGE',
					addclass: 'datetimerange', 
					formatter: Table.api.formatter.datetime
				}, 
				{
					visible:false,//列表不显示,模糊查询显示
					field: 'userphone',
					title: __('客户手机')
				},
				{
					operate:false,//模糊查询不显示
					field: '',
					title: __('客户'),
					formatter: Controller.api.user_info,
					
				},{
					field: 'money',
					title: __('金额')
				},{
					field: 'type',
					title: __('支付方式'),
					searchList: {"hot": __('微信支付'), "index": __('余额支付')}, operate: 'FIND_IN_SET', formatter: Table.api.formatter.label
				},{
					operate:false,
					field: 'status',
					title: __('支付状态')
				},{
					operate:false,//模糊查询不显示
					field: 'remark',
					title: __('备注')
				},
				{
					operate:false,
				    field: 'buttons',
				    title: __('操作'),
				    table: table,
				    events: Table.api.events.operate,
				    buttons: [
				        {
				            name: 'detail',
				            text: __('查看'),
				            title: __('查看'),
				            classname: 'btn btn-xs btn-primary btn-dialog',
				            url: '/shijiu.php/chase/to_shop/detail'
				        },
						{
						    name: 'gathering',
						    text: __('收款'),
						    title: __('收款'),
						    classname: 'btn btn-xs btn-success btn-dialog',
						    url: '/shijiu.php/chase/real_order/index'
						},
				        {
				            name: 'addtabs',
				            text: __('取消'),
				            title: __('取消'),
				            classname: 'btn btn-xs btn-warning btn-addtabs',
				        }
				    ],
				    formatter: Table.api.formatter.buttons
				}
				]
					
			});
				// 为表格绑定事件
				Table.api.bindevent(table);
			$('.myTabContent').on('click', '.btn-add-order', function() {
				console.log('11111xx')
				Fast.api.open('/shijiu.php/chase/real_order/index', '开单',{area:['100%', '100%']})
					
			})
			
			  
			// $('#myTabContent').on('click', '.btn-detail', function() {
			// 	console.log('11111xx')
			// 	Fast.api.open('/shijiu.php/chase/to_shop/detail', '查看')
					
			// })
			
		Controller.api.bindevent();
		},
        api: {
			order_info:function(value, row, index){
				 var number = '订单编号:' + row.orderid + '<br>';
				 var time = '下单时间:' + row.ordertime + '<br>';
				 return number  + time 
			},
			user_info:function(value, row, index){
				 var name ="客户名称:"+ row.username + '<br>';
				 var phone ="客户手机:"+ row.userphone + '<br>';
				 var grade ="用户等级:"+ row.usergrade + '<br>';
				 return name  + phone + grade
			},
			serve_name:function(value, row, index){
				console.log(value, row, index)
				if(row.serve.length>0){
					let serve_html=`
					<table innertable class="table table-bordered" style="border-top:0;border-bottom:0">
					`
					for (var i = 0; i < row.serve.length; i++) {
						console.log(row.serve[i].name)
						serve_html+=`
								<tr style="${i % 2 == 0 ?'border-top:0':i==row.serve.length-1?'border-bottom:0':''}"><td style="${i % 2 == 0 ?'border-top:0':i==row.serve.length-1?'border-bottom:0':''}">${row.serve[i].name}</td></tr>
							`
					}
					return serve_html+=`</table>`
				}
			},
			serve_price:function(value, row, index){
				console.log(value, row, index)
				if(row.serve.length>0){
					let serve_html=`
					<table id="innertable" class="table table-bordered" style="border-top:0;border-bottom:0">
					`
					for (var i = 0; i < row.serve.length; i++) {
						console.log(row.serve[i].price)
						serve_html+=`
								<tr style="${i % 2 == 0 ?'border-top:0':i==row.serve.length-1?'border-bottom:0':''}"><td style="${i % 2 == 0 ?'border-top:0':i==row.serve.length-1?'border-bottom:0':''}">${row.serve[i].price}</td></tr>
							`
					}
					return serve_html+=`</table>`
				}
			},
			serve_count:function(value, row, index){
				console.log(value, row, index)
				if(row.serve.length>0){
					let serve_html=`
					<table id="innertable" class="table table-bordered" style="border-top:0;border-bottom:0">
					`
					for (var i = 0; i < row.serve.length; i++) {
						console.log(row.serve[i].count)
						serve_html+=`
								<tr style="${i % 2 == 0 ?'border-top:0':i==row.serve.length-1?'border-bottom:0':''}"><td style="${i % 2 == 0 ?'border-top:0':i==row.serve.length-1?'border-bottom:0':''}">x${row.serve[i].count}</td></tr>
							`
					}
					return serve_html+=`</table>`
				}
			},
			serve_technician:function(value, row, index){
				console.log(value, row, index)
				if(row.serve.length>0){
					let serve_html=`
					<table id="innertable" class="table table-bordered " style="border-top:0;border-bottom:0">
					`
					for (var i = 0; i < row.serve.length; i++) {
						console.log(row.serve[i].technician)
						serve_html+=`
								<tr style="${i % 2 == 0 ?'border-top:0':i==row.serve.length-1?'border-bottom:0':''}"><td style="${i % 2 == 0 ?'border-top:0':i==row.serve.length-1?'border-bottom:0':''}">x${row.serve[i].technician}</td></tr>
							`
					}
					return serve_html+=`</table>`
				}
			},
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        },
		
    };
    return Controller;
});